class Setting {
  mixin = {
    data() {
      return {
        navList: [{
            icon: require("@/assets/imgs/user/mysetting.png"),
            name: "My Settings",
            status: 0,
          },
          {
            icon: require("@/assets/imgs/user/myaddress.png"),
            name: "My Address",
            status: 0,
          },
          {
            icon: require("@/assets/imgs/user/changep.png"),
            name: "Change Password",
            status: 0,
          },
        ],
        navIndex: 0,
        form: {
          nick_name: "",
          job_title: "",
          description: "",
        },
        pageTitle: "",
        state: "default",
        checked: false,
        selectIndex: 0,
        loading: false,
      }
    },
    computed: {
      userInfo() {
        let userInfo = this.$store.state.user.userInfo;
        this.form.nick_name = userInfo.nick_name;
        this.form.job_title = userInfo.job_title;
        this.form.description = userInfo.description;
        return userInfo;
      },
      countryList() {
        return this.$store.state.over.countryList;
      },
      refreshAddress() {
        return this.$store.state.user.refreshAddress;
      },
      addressList() {
        return this.$store.state.user.addressList;
      },
    },
    activated() {
      this.navIndex = this.$route.query.navIndex == undefined ? 0 : this.$route.query.navIndex;
    },
    methods: {
      clickNav(index) {
        if (index == 0) {
          this.$router.replace({
            path: "/user/setting",
          });
        } else if (index == 1) {
          this.$router.replace({
            path: "/user/address",
          });
        } else if (index == 2) {
          this.$router.replace({
            path: "/user/changepassword",
          });
        }
      },
      clickAccount() {
        this.$toast("Account cannot be modified");
      },
      //选中国家
      counConfirm(val) {
        this.userInfo.country_code = val.code;
        this.userInfo.country_name = val.name;
        this.country.show = false;
      },
      //取消选中
      onCancel() {
        this.country.show = false;
      },
      //点击底部按钮
      clickLogin() {
        if (this.navIndex == 0) {
          this.tips.startLoadingToast();
          this.$store
            .dispatch("user/updateUserInfo", this.form)
            .then((res) => {
              this.tips.closeToast();
              if (res.code == 0 && res.data != undefined) {
                localStorage.setItem("userInfo", JSON.stringify(res.data));
                this.$store.commit("user/setUserInfo", res.data); //保存登陆信息
                this.$toast("Saved successfully");
                //this.$router.back();
              } else {
                this.$toast(res.msg);
              }
            })
            .catch((err) => {
              console.log(err);
              tips.closeToast();
            });
        }
      },
    }
  }
}
export default new Setting();
